<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/header.php");
?>
<section>
<hgroup>
<h1>Probleem verwijderen</h1>
</hgroup>

<?php 
    if (isset($_POST["bevestiging"]))
    {
        $query1 = "SELECT * FROM screeningproblem WHERE Id=".$_POST["screeningproblemid"]."";
        $result1 = mysql_query($query1) or die (mysql_error());
        while ($row1 = mysql_fetch_array($result1))
        {
            $query2 = "SELECT * FROM itemproblem WHERE Id=".$row1['ItemProblemId']."";
            $result2 = mysql_query($query2) or die ("FOUT1: " . mysql_error());
            while ($row2 = mysql_fetch_array($result2)){
                $problem =  $row2['Name'];
            }
        }

        $query2= "DELETE FROM screeningproblem WHERE Id='".$_POST['screeningproblemid']."'";
        $result2 = mysql_query($query2) or die ("FOUT2: " . mysql_error());
        if ($result2)
        {
            echo ("<p>Probleem " .$problem . " is verwijderd<br>\n");
            echo ("<a href=\"screening.php?id=".$_POST["screeningid"]."\">Terug naar het screenings-rapport.</a></p>");
        }
    }
    else
    {
        $query1 = "SELECT * FROM screeningproblem WHERE Id=".$_GET["screeningproblemid"]."";
        $result1 = mysql_query($query1) or die (mysql_error());
        while ($row1 = mysql_fetch_array($result1))
        {
            $query2 = "SELECT * FROM itemproblem WHERE Id=".$row1['ItemProblemId']."";
            $result2 = mysql_query($query2) or die ("FOUT1: " . mysql_error());
            while ($row2 = mysql_fetch_array($result2)){
                $id = $row2['Id'];
                echo "<p>Probleem-id = " . $row2['Id'] . "<br>\n";
                echo "<p>Probleem = " . $row2['Name'] . "<br>\n";
            }
        }
?>
<form action="<?php echo($_SERVER["PHP_SELF"]);?>" method="post">
    <p>
        <input type="hidden" name="bevestiging" value="1" />
        <input type="hidden" name="id" value="<?php echo($id);?>" />
        <input type="hidden" name="screeningid" value="<?php echo($_GET["screeningid"]);?>" />
        <input type="hidden" name="screeningproblemid" value="<?php echo($_GET["screeningproblemid"]);?>" />
        <input type="submit" value="Ja, verwijderen" />
        <input type="button" value="Nee, terug" onclick="javascript:history.back();" />
    </p>
</form>
<?php
    }
?>

</section>
<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/footer.php");
?>
